<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class WdminPage extends Controller {

    const TPL = './views/wdminpage/';

    public function __construct($ControllerName, $Action, $QueryString) {
        parent::__construct($ControllerName, $Action, $QueryString);
        $this->loadModel('Db');
    }

    /**
     * 报表首页
     */
    public function home() {
        $this->show();
    }

    /**
     * 代发货订单
     */
    public function orders_toexpress() {
        $this->show(self::TPL . 'orders/orders_toexpress.tpl');
    }

    /**
     * 快递中订单
     */
    public function orders_expressing() {
        $this->show(self::TPL . 'orders/orders_expressing.tpl');
    }

    /**
     * 所有订单
     */
    public function orders_all() {
        $this->show(self::TPL . 'orders/orders_all.tpl');
    }

    /**
     * 退货申请
     */
    public function orders_toreturn() {
        $this->show(self::TPL . 'orders/orders_toreturn.tpl');
    }

    public function orders_unpay() {
        $this->show(self::TPL . 'orders/orders_unpay.tpl');
    }

    /**
     * 所有产品
     */
    public function list_products() {
        $this->show(self::TPL . 'products/list_products.tpl');
    }

    /**
     * 编辑商品信息
     * @param type $Query
     */
    public function iframe_alter_product($Query) {
        $this->loadModel('Product');
        $mod = $Query->mod;
        $serials = $this->Product->getSerials();
        $categorys = $this->Product->getAllCats();
        if ($mod == 'edit') {
            $pid = $this->pGet('id');
            $productInfo = $this->Product->getProductInfo($pid);
            $this->Smarty->assign('ed', true);
            $this->Smarty->assign('pd', $productInfo);
            $this->Smarty->assign('cat', $productInfo['product_cat']);
        } else {
            $cat = $Query->catid;
            $this->Smarty->assign('ed', false);
            $this->Smarty->assign('cat', $cat);
        }
        $this->Smarty->assign('categorys', $categorys);
        $this->Smarty->assign('serials', $serials);
        $this->Smarty->assign('mod', $mod);
        $this->show(self::TPL . 'products/iframe_alter_product.tpl');
    }

    /**
     * 
     * @param type $Query
     */
    public function iframe_list_product($Query) {
        $cat = $Query->cat ? intval($Query->cat) : 0;
        $page = $Query->page ? intval($Query->page) : 0;
        $part = isset($Query->part);
        $this->cacheId = $cat . $page . $part;
        if (!$this->isCached()) {
            $listLim = 50;
            $lim = $Query->page * $listLim . "," . $listLim;
            $this->loadModel('Product');
            $productList = $this->Product->getProductList('product_id DESC', $lim, $cat);
            $this->Smarty->assign('cat', $cat);
            $this->Smarty->assign('page', $page);
            $this->Smarty->assign('list', $productList);
            $this->Smarty->assign('listCount', count($productList));
        }
        if (!$part) {
            $this->show(self::TPL . 'products/iframe_list_products.tpl');
        } else {
            $this->show(self::TPL . 'products/iframe_list_products_jsarray.tpl');
        }
    }

    public function alter_products() {
        $this->show(self::TPL . 'products/alter_products.tpl');
    }

    public function alter_products_category() {
        $this->show(self::TPL . 'products/alter_products_category.tpl');
    }

    public function alter_category($Query) {
        $id = intval($Query->id);
        // ch
        if (is_numeric($id)) {
            $this->loadModel('Product');
            $cati = $this->Product->getCatInfo($id);
            $this->cacheId = hash('md4', $id . $cati['cat_name']);
            $this->Smarty->assign('id', $id);
            $this->Smarty->assign('cat', $cati);
            $this->show(self::TPL . 'products/alter_category.tpl');
        }
    }

    public function gmess_list() {
        $this->show(self::TPL . 'gmess/gmess_list.tpl');
    }

    public function gmess_sent() {
        $this->show(self::TPL . 'gmess/gmess_sent.tpl');
    }

    public function gmess_send() {
        $this->show(self::TPL . 'gmess/gmess_send.tpl');
    }

    public function email_send() {
        $this->show(self::TPL . 'gmess/email_send.tpl');
    }

    public function gmess_edit() {
        $this->show(self::TPL . 'gmess/gmess_edit.tpl');
    }

    public function list_customers() {
        $this->show(self::TPL . 'customers/list_customers.tpl');
    }

    /**
     * 商品回收站
     */
    public function deleted_products() {
        $this->loadModel('Product');
        $productList = $this->Product->getDeletedProducts();
        $this->Smarty->assign('list', $productList);
        $this->show(self::TPL . 'products/deleted_products.tpl');
    }

    public function alter_product_specs() {
        $this->loadModel('Product');
        $specs = $this->Product->getSpecs();
        $this->Smarty->assign('specs', $specs);
        $this->show(self::TPL . 'products/alter_product_specs.tpl');
    }

    public function list_customer_orders($Query) {
        $cid = $Query->id;
        $this->Smarty->assign('cid', $cid);
        $this->show(self::TPL . 'customers/list_customer_orders.tpl');
    }

    public function list_companys() {
        $this->loadModel('mCompany');
        $companys = $this->mCompany->getCompanys();
        foreach ($companys as &$c) {
            $c['fellows'] = $this->mCompany->getCompanyFellows($c['uid']);
            $c['fellow_count'] = count($c['fellows']);
            $c['income_total'] = $this->mCompany->getCompanyIncomeCount($c['uid'], false);
            $c['income_month'] = $this->mCompany->getCompanyIncomeCount($c['uid'], false, true);
            $c['income_unset'] = $this->mCompany->getCompanyIncomeCount($c['uid'], 0, false);
        }
        $this->Smarty->assign('companys', $companys);
        $this->show(self::TPL . 'company/list_companys.tpl');
    }

    public function company_requests() {
        $this->loadModel('mCompany');
        $companys = $this->mCompany->getCompanys(0);
        $this->Smarty->assign('companys', $companys);
        $this->show(self::TPL . 'company/company_requests.tpl');
    }

    public function company_withdrawal() {
        $this->loadModel('mCompany');
        $wdList = $this->mCompany->getCompanyCashs();
        $this->Smarty->assign('wdlist', $wdList);
        $this->show(self::TPL . 'company/company_withdrawal.tpl');
    }

    public function list_company_users($Query) {
        $this->loadModel('mCompany');
        $users = $this->mCompany->getCompanyFellows($Query->id);
        $this->Smarty->assign('list', $users);
        $this->show(self::TPL . 'company/list_company_users.tpl');
    }

    public function setting_base(){
        
    }
    
}
